﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using DR.WebUI.Models.Developer;
using DR.WebUI.Models.Manager;
using DR.WebUI.Code.ModelBinders;
using DR.WebUI.Models;

namespace DR.WebUI
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
             "TaskView",
             "Manager/TaskView/{page}",
             new { controller = "Manager", action = "TaskView", page = 1 },
             new { page = @"\d+" }
             );

            routes.MapRoute(
             "ReportsOverviewDeveloper",
             "Developer/MyReports/{page}",
             new { controller = "Developer", action = "MyReports", page = 1 },
             new { page = @"\d+" }
             );

            routes.MapRoute(
              "MyReports",
              "Manager/ReportsOverview/{page}",
              new { controller = "Manager", action = "ReportsOverview", page = 1 },
              new { page = @"\d+" }
              );      

            routes.MapRoute(
              "ReportEdit",
              "Developer/EditReport/{reportID}",
              new { controller = "Developer", action = "EditReport", reportID = 1 }
              );

            routes.MapRoute(
             "Edit",
             "Project/Edit/{projectID}",
             new { controller = "Project", action = "Edit", projectID = 1 }
             );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);

            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory());

            ModelBinders.Binders.Add(typeof(DR.WebUI.Models.Manager.ReportFilter), new ManagerReportFilterModelBinder());
            ModelBinders.Binders.Add(typeof(DR.WebUI.Models.Developer.ReportFilter), new DeveloperReportFilterModelBinder());
            ModelBinders.Binders.Add(typeof(DR.WebUI.Models.Project.ProjectFilter), new ProjectFilterModelBinder());
            ModelBinders.Binders.Add(typeof(DR.WebUI.Models.Account.CurrentUser), new CurrentUserModelBinder());
        }
    }
}